//
//  CHShadowCard.swift
//  Checked
//
//  Created by Shinolr on 1/10/19.
//  Copyright © 2019 shinolr_go. All rights reserved.
//

import UIKit

class CHShadowCard: UIView {
    
    var shadowView: UIView!
    @IBOutlet weak var contentView: UIView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        shadowView.layer.shadowColor = UIColor.gray.cgColor
        shadowView.layer.shadowOpacity = 0.2
        shadowView.layer.shadowRadius = 10
        shadowView.layer.shadowOffset = CGSize(width: 0, height: 3)
        contentView.layer.cornerRadius = 10
        contentView.layer.masksToBounds = true
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        xibSetup()
    }
    
    func xibSetup() {
        shadowView = loadViewFromNib()
        shadowView.frame = bounds
        shadowView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        insertSubview(shadowView, at: 0)
    }
    
    func loadViewFromNib() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil).first as? UIView
        return view!
    }
}
